const { query } = require("../utils/mysql");
async function loginSql(username, password) {
  const sql = `select * from user where username= ? and password= ? `;
  const result = await query(sql, [username, password]);
  return result;
}

async function loginByTel() {}
// 用户是否存在
async function isUsernameExist(username) {
  const sql = `select * from user where username= ?`;
  const result = await query(sql, [username]);
  if (result.length) {
    return true;
  } else {
    return false;
  }
}

async function registerSql({ username, password, nickname, tel, avatar, age, sex }) {
  const sql = `INSERT INTO user (id, username, password, tel, nickname, avatar, age, sex) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?)`;
  const result = await query(sql, [username, password, tel, nickname, avatar, age, sex])
  return result
}

function getCodeSql() {}

const login = {
  loginSql,
  loginByTel,
  registerSql,
  getCodeSql,
  isUsernameExist,
};

module.exports = login;
